package models

import (
	"kop/libs/database"
	"kop/modules/guild/configuration"
	"kop/modules/guild/entity"
)

func GetSkills(roleID int32) []entity.GuildSkill {

	var data []entity.GuildSkill
	database.DB.Where("role_id = ?", roleID).Find(&data)

	for _, conf := range configuration.GuildSkillConfigs {

		var find bool

		for _, skill := range data {
			if conf.SkillID == skill.SkillID {
				find = true
				break
			}
		}

		if !find {
			var skill entity.GuildSkill
			skill.RoleID = roleID
			skill.SkillID = conf.SkillID
			database.DB.Create(&skill)
			data = append(data, skill)
		}
	}

	return data
}
